package com.ailk.tcm.hffw.android.utils;

import java.text.SimpleDateFormat;
import java.util.Date;

public class TimeUtil {
	public static SimpleDateFormat humanTimeFormat = new SimpleDateFormat("HH:mm");
	public static SimpleDateFormat humanMonthFormat = new SimpleDateFormat("MM-dd HH:mm");
	public static SimpleDateFormat humanDateFormat = new SimpleDateFormat("yy-MM-dd HH:mm");
	
	public static String humanTime(Date time, Date now){
		if(time == null){
			return null;
		}
		int year = time.getYear();
		int month = time.getMonth();
		int day = time.getDay();
		
		if(now == null){
			now = new Date();
		}
		int nowYear = now.getYear();
		int nowMonth = now.getMonth();
		int nowDay = now.getDay();
		if(nowYear == year){
			if(nowMonth == month){
				int diff = nowDay - day;
				switch (diff) {
				case 0:
					return humanTimeFormat.format(time);
				case 1:
					return "昨天  " + humanTimeFormat.format(time);
				case -1:
					return "明天  " + humanTimeFormat.format(time);
				default:
					return humanMonthFormat.format(time);
				}
			}else{
				return humanMonthFormat.format(time);
			}
		}else{
			return humanDateFormat.format(time);
		}
	}
}
